﻿/* San Antonio Health Center Patient Information Management System
 * 
 * =========================================
 * Description: Add Prenatal CheckUp
 * -adds a prenatal type of checkup
 * -connects and saves in database
 * 
 * Note:
 * -accept button no redirection yet,
 * but with function that saves to database
 * 
 * Functions:
 * -Account searching for family member
 * 
 * -----------------------------------------
 * Date Finished: February 22, 2010
 * Author: Nikko Fernando O. Santillan
 * =========================================
 * */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace sahcpims
{
    public partial class prenatal : Form
    {
        public prenatal()
        {
            InitializeComponent();
        }

        public int familyNumber;
        public string firstName;
        public string middleName;
        public string surname;
        public string memberBDate;
        public int weight;
        public string checkUpType;

        public int employeeNumber;
        public string employeeName;

        public int doFlag = 0;

        public void displayInformation()
        {
            familyInformationLabel.Text = firstName + " " + middleName + " " + surname;
            familyNumberMismo.Text = familyNumber.ToString();
            bDateInfo.Text = memberBDate;
            weightInfo.Text = weight.ToString();
            checkupTypeInfo.Text = checkUpType;

            empNumLabel.Text = employeeNumber.ToString();
            employeeLabel.Text = employeeName;
        }

        private void acceptMemberButton_Click(object sender, EventArgs e)
        {


            /** Connection String: Provider of the connection and the source of data **/
            string conString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\\SAHCPIMS_database.mdb";

            /** create instance of the connection with the connection string as parameter **/
            OleDbConnection conn = new OleDbConnection(conString);

            /** 
             * Creating an instance of the DataSet which represents an in-memory cache of data
             * This is where the result of the database query will be stored
            **/
            DataSet ds = new DataSet();

            conn.Open();

            //for connection to the database
            try
            {
                OleDbDataAdapter tagalagay = new OleDbDataAdapter("INSERT into Prenatal "
                                          + "values('" + familyNumber + "','" + firstName + "','" + middleName + "','" + surname + "','" +  monthComboBox.Text.ToString() + "/" + dayComboBox.Text.ToString() + "/" + yearComboBox.Text.ToString() + "','" + monthexpectedDeliveryCombo.Text.ToString() + "/" + dayExpectedDeliveryCombo.Text.ToString() + "/" + yearExpectedDeliveryCombo.Text.ToString() + "','" + int.Parse(gestationTextBox.Text) + "','" + monthLMPCombo.Text.ToString() + "/" + dayLMPCombo.Text.ToString() + "/" + yearLMPCombo.Text.ToString() + "','" + int.Parse(gravidaTextBox.Text) + "','" + int.Parse(paraTextBox.Text) + "','" + monthtoxoidCombo.Text.ToString() + "/" + dayToxoidCombo.Text.ToString() + "/" + yearToxoidCombo.Text.ToString() + "')",conn);

                tagalagay.Fill(ds);
                doFlag = 0;

            }
            //catches exception if the user input is invalid
            catch (FormatException)
            {

                memberVerificationLabel.Text = "Message: Invalid Input. Try Again.";
                doFlag = 1;

            }
            //catches exception if the input is already in the database or the input is not saved in the database
            catch (OleDbException)
            {
                memberVerificationLabel.Text = "Message: Data not Saved in Database. There's a Problem with the Input (it is either it already exists, nothing in input or wrong format in input).";
                doFlag = 1;

            }

             //closes database
                conn.Close();

                //if registration is successful, the form is disabled
                if (doFlag == 0)
                {
                    
                    checkUpDateSuccess.Text = "Checkup Date: " + monthComboBox.Text.ToString() + "/" + dayComboBox.Text.ToString() + "/" + yearComboBox.Text.ToString();
                    expectedDeliverySuccess.Text = "Expected Delivery Date: " + monthexpectedDeliveryCombo.Text.ToString() + "/" + dayExpectedDeliveryCombo.Text.ToString() + "/" + yearExpectedDeliveryCombo.Text.ToString();
                    ageOfGestationSuccess.Text = "Age of Gestation: " + gestationTextBox.Text;
                    gravidaSuccess.Text = "Gravida: " + gravidaTextBox.Text;
                    paraSuccess.Text = "Para: " + paraTextBox.Text;
                    LMPSuccess.Text = "LMP: " + monthLMPCombo.Text.ToString() + "/" + dayLMPCombo.Text.ToString() + "/" + yearLMPCombo.Text.ToString();
                    toxoidSuccess.Text = "Toxoid: " + monthtoxoidCombo.Text.ToString() + "/" + dayToxoidCombo.Text.ToString() + "/" + yearToxoidCombo.Text.ToString();

                    panel2.Visible = false;
                    panel3.Visible = false;
                    panel4.Visible = false;
                    panel5.Visible = false;
                    checkUpDate.Visible = false;
                    expectedDelivery.Visible = false;
                    paraLabel.Visible = false;
                    gravidaLabel.Visible = false;
                    gestationLabel.Visible = false;
                    LMPLabel.Visible = false;
                    label21.Visible = false;
                    gestationTextBox.Visible = false;
                    paraTextBox.Visible = false;
                    gravidaTextBox.Visible = false;


                    acceptMemberButton.Visible = false;
                    addPrenatalLabel.Text = "Add Member Check Up Success!";

                    backButton.Visible = true;
                   


                }
        }

        private void logOutButton_Click(object sender, EventArgs e)
        {
            logIn logout = new logIn();
            logout.Visible = true;
            this.Visible = false;

        }

        private void backButton_Click(object sender, EventArgs e)
        {
            homePage home = new homePage();
            home.homeEmpName = employeeName;
            home.homeEmpNum = employeeNumber;
            home.putAccountInfo();

            home.Visible = true;
            this.Visible = false;
        }



    }
}
